﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Model;
using BLL;
using Newtonsoft.Json;

namespace EstateappraisalApi.Controllers
{
    /// <summary>
    /// 项目管理
    /// </summary>
    public class ProjectController : ApiController
    {

        Basic_InfoBLL bll = new Basic_InfoBLL();
        Loan_InfoBLL lbll = new Loan_InfoBLL();
        // GET api/project

         /// <summary>
         /// 所有的项目
         /// </summary>
         /// <returns></returns>
        public string Get()
        {
            var s=bll.ShowBasic_Info();
            return JsonConvert.SerializeObject(s);
        }

        /// <summary>
        /// 根据用户编号查找对应的项目
        /// </summary>
        /// <returns></returns>
        public List<dynamic> Get(int User_Id)
        {
            var s = bll.Show(User_Id);
            return s;
        }


        /// <summary>
        /// 根据项目状态查找对应的项目
        /// </summary>
        /// <returns></returns>
        public List<Basic_Info> Get(string basic_State)
        {
            var s = bll.ShowBasic_Info(basic_State);
            return s;
        }

        /// <summary>
        /// 根据勘察员编号和项目状态查找项目基本信息
        /// </summary>
        /// <returns></returns>
        public string Get(int survey, string basic_State)
        {
            var s = bll.Show(survey, basic_State);
            return JsonConvert.SerializeObject(s);
        }

        /// <summary>
        /// 根据评估员编号和项目状态查找项目基本信息
        /// </summary>
        /// <returns></returns>
        public string Get(string basic_State, int evaluation)
        {
            var s = bll.ShowBasic_Info(basic_State, evaluation);
            return JsonConvert.SerializeObject(s);
        }


        // POST api/project
        /// <summary>
        /// 添加项目信息
        /// </summary>
        /// <param name="Blist"></param>
        /// <returns></returns>
        public int Post([FromBody]Basic_Info Blist)
        {
            var num=bll.Pnum() + 1;
            Blist.projectNumber = num.ToString();
            Blist.User_Id = 1;
            Blist.basic_CreateTime = DateTime.Now.ToString();
            Blist.basic_State = 90;
            if (bll.AddBasic_Info(Blist))
            {
                return int.Parse(Blist.projectNumber);
            }
            else
            {
                return 0;
            }
        }

        // PUT api/project/5
        // <summary>
        // 修改项目信息
        // </summary>
        // <param name="basic_id"></param>
        // <param name="Blist"></param>
        // <returns></returns>
        public int Put(int basic_id, [FromBody]Basic_Info Blist)
        {
            Blist.basic_CreateTime = DateTime.Now.ToString();
            Blist.basic_State = 90;
            if (bll.UpdBasic_Info(Blist, basic_id))
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }

      
        /// <summary>
        /// 删除项目
        /// </summary>
        /// <param name="id"></param>
        [HttpDelete]
        public int Delete(int id)
        {
            Basic_Info m = new Basic_Info();
            m.basic_id = id;
            if (bll.DelBasic_Info(m))
            {
                return 1;
            }
            else
            {
                return 0;
            }

        }
        



    }
}
